using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Script.Serialization;

namespace TimeTableManagement.Entities
{
    /// <summary>
    /// 
    /// </summary>
    public class Tb_Education
    {
        public int id { get; set; }
        [Required]
        [Display(Name = "Code")]
        public string code { get; set; }
        [Required]
        [Display(Name = "Name")]
        public string name { get; set; }
         [Display(Name = "Max Credit")]
        public Nullable<int> maxcredit { get; set; }
        [Display(Name = "Count Term")]
        public Nullable<int> countterm { get; set; }
        [Display(Name = "Department")]
        public Nullable<int> department { get; set; }
        public string listcourse { get; set; }
        [DataType(DataType.MultilineText)]
        [System.Web.Mvc.AllowHtml]
        public string description { get; set; }
        public virtual Tb_Department Tb_Department { get; set; }
        /// <summary>
        /// Lay ra danh sach cac mon hoc trong chuong trinh hoc
        /// </summary>
        /// <param name="id">id cua chuong trinh hoc (id_education)</param>
        /// <returns>List cac doi tuong EduList</returns>
        public List<EduList> getCoureforEdu(int id)
        {
            QLSVContext db = new QLSVContext();
            Tb_Education tb_edu = db.Tb_Education.Find(id);
            db.Dispose();
            String jsontext = tb_edu.listcourse.ToString();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            List<EduList> listedu = jss.Deserialize<List<EduList>>(jsontext);
            if (listedu != null)
                return listedu;
            return null;
        }
    }
    /// <summary>
    /// Cau truc Json
    /// [{"term":Hoc_Ky,"idcourse":Id_Course,"code":"Ma_Mon","name":"Ten_Mon"}]
    /// </summary>
    public class EduList
    {
        string _code; //ma mon hoc
        int _hk; //hoc ky
        int _idcourse; //id mon hoc
        string _name; //ten mon
        public string name
        {
            get { return _name; }
            set { _name = value; }
        }
        public string code
        {
            get { return _code; }
            set { _code = value; }
        }
        public int term
        {
            get { return _hk; }
            set { _hk = value; }
        }
        public int idcourse
        {
            get { return _idcourse; }
            set { _idcourse = value; }
        }
        
    }
}

